package com.yq.juc.study;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName CallableDemo
 * @Description callable
 * 适配的思想
 * 并发异步保证回滚出来
 * 高并发最厉害的是控制
 * @Author yaoqiang
 * @Date 2020/11/23 15:31
 * @Version 1.0
 */
public class CallableDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<Integer> futureTask=new FutureTask<>(new MyThread2());
        new Thread(futureTask,"AA").start();//Thread thread1=new Thread(futureTask,"AA");thread1.start();
        new Thread(futureTask,"BB").start();
        int result01=100;
        int result02=futureTask.get();
        while (!futureTask.isDone()){
        }
        System.out.println("mian***");

        System.out.println(result01+result02);

    }

}

class MyThread implements Runnable{
    @Override
    public void run() {
    }
}

class MyThread2 implements Callable<Integer>{

    @Override
    public Integer call() throws Exception {
        System.out.println("***call()");
        TimeUnit.SECONDS.sleep(2);
        return 1024;
    }
}
